package com.deep.test

import org.apache.spark.mllib.linalg._
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.stat.Statistics
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author sw
 * @create 2023-06-02 14:03
 */
object Test10 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("ALS")
    val sc = new SparkContext(conf)
    sc.setLogLevel("WARN")

    val v1: Vector = sc.textFile("data/iris.data").map(_.split(",")).map(p => Vectors.dense(p(0).toDouble, p(1).toDouble, p(2).toDouble, p(3).toDouble)).first
    val v2: Vector = sc.textFile("data/iris.data").map(_.split(",")).map(p => Vectors.dense(p(0).toDouble, p(1).toDouble, p(2).toDouble, p(3).toDouble)).take(2).last

    //    val mat: Matrix = Matrices.dense(2, 2, Array(v1(0), v1(1), v2(0), v2(1)))
    //    println(mat)
    //
    //    val a = Statistics.chiSqTest(mat)
    //    println(a)

    //    val c1 = Statistics.chiSqTest(v1, v2)
    //    println(c1)
    //
    val data = sc.textFile("data/iris.data")
    val obs = data.map { line =>
      val parts = line.split(',')
      LabeledPoint(if (parts(4) == "Iris-setosa") 0.toDouble else if (parts(4) == "Iris-versicolor") 1.toDouble
      else 2.toDouble, Vectors.dense(parts(0).toDouble, parts(1).toDouble, parts(2).toDouble, parts(3).toDouble))
    }
    //    println(obs)
    val featureTestResults = Statistics.chiSqTest(obs)

    featureTestResults.
      foreach {
        println
      }

    val test = sc.textFile("data/iris.data").map(_.split(",")).map(p => p(0).toDouble)
    val myCDF: Double => Double = (p=>p*2)
    val testResult2 = Statistics.kolmogorovSmirnovTest(test, myCDF)
    println(testResult2)

  }
}
